<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="infoList">
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">{{ (scope.$index + 1) }}</template>
      </el-table-column>
      <el-table-column label="荣誉名称" align="center" prop="honorName" />
      <el-table-column label="获奖时间" align="center" prop="awardDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.awardDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="荣誉等级" align="center" prop="honorLevel" />
      <el-table-column label="荣誉扫描附件" align="center" prop="attach">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="viewAttachments(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="附件列表" :visible.sync="dialogVisible" width="50%">
      <div
        v-for="(attach, index) in attachments"
        :key="index"
        style="margin-bottom: 10px;display: flex;justify-content: center;"
      >
        <img :src="attach.attach" alt />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getInfo, getAttachment } from "@/api/system/honor";

export default {
  props: {
    row: {
      type: Object,
      required: true // 必须传递该prop
    }
  },
  name: "Info",
  data() {
    return {
      // 荣誉信息表格数据
      infoList: [],
      // 人才id
      talentId: null,
      attachments: [],
      dialogVisible: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询荣誉信息列表 */
    getList() {
      this.loading = true;
      this.talentId = this.row.id;
      getInfo(this.talentId).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    viewAttachments(id) {
      getAttachment(id)
        .then(response => {
          this.attachments = response.rows;
          this.dialogVisible = true;
        })
        .catch(error => {
          console.error("Error fetching attachments:", error);
        });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/info/export",
        {
          ...this.queryParams
        },
        `info_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
